package 极客时间.concurrence.并发编程理论基础.面向对象写多线程;

public class VolatileExample {
    int x = 0;
    volatile boolean v = false;

    public void writer() {
        x = 42;
        v = true;
    }

    public void reader() {
        if (v == true) { // 这里x会是多少呢？
            System.out.println(x);
        }
    }

    public static void main(String[] args) {
        VolatileExample v = new VolatileExample();
        v.writer();
        v.reader();
    }
}